
********************************************************************************
* Analysis Code for CES Regional Hegemony Code
********************************************************************************

* Paul Musgrave
* rpm47@georgetown.edu
* For Paul Musgrave and Dov Levin

********************************************************************************
* Stata Packages Required (Note)
********************************************************************************

/*

Replication users will need the following packages available from SSC or other
repositories

net install cleanplots, from("https://tdmize.github.io/data/cleanplots") replace

ssc install catplot

ssc install coefplot

ssc install esttab

ssc install mylabels

ssc install grc1leg

ssc install statplot

*/


********************************************************************************
* Stata Cruft
********************************************************************************

clear all

version 18

set more off


set scheme plotplainblind

******** EDIT DIRECTORY STRUCTURE TO FIT YOUR COMPUTER ********

global MyProject "~/Dropbox/0001 Academic Projects/Ongoing/0155 Voting Abroad Purpose/Replication/Upload/"


********************************************************************************
* Importing Data for Experiment
********************************************************************************

use "${MyProject}CCES2022processedUPLOAD.dta", clear

recode hispanic (2 = 0)

lab def HISPANIC 0 "Not Hispanic" 1 "Hispanic", modify

********************************************************************************
* Summary Tables
********************************************************************************


lab var hegemony_contribute "Contribute"
lab var hegemony_assist "Experts"
lab var hegemony_fabricate "Fabricate"
lab var hegemony_promise "Promise"
		
********************
* Appendix Table A1

lab def collegelab 0 "No degree" 1 "Degree"

lab val college collegelab

lab def whitelab 0 "Not White-only" 1 "White-only"

lab val white whitelab

dtable age i.white i.gender4 i.college i.pid3 i.hispanic ///
		, by(tookpost)															///
        nformat(%6.0f	)														///
		title("CES Population Summary" "\label{tab:cessummary}")					///
		export("${MyProject}AppendixTableA1.tex", replace  tableonly  )

		
********************
* Appendix Table A6

dtable age female pid3 college white hispanic									///
	,by(hegemony_high_chance) nformat(%8.2g)									///
	export("${MyProject}AppendixTableA6.tex", replace tableonly) ///
	title("Hegemony Experiment (Chance) \label{tab:hegemonyBalanceChance}")
	

********************
* Appendix Table A7

dtable age female pid3 college white hispanic									///
	, by(hegemony_region) nformat(%8.2g)										///
	export("${MyProject}AppendixTableA7.tex", replace tableonly) 		///
	title("Hegemony Experiment (Region)  \label{tab:hegemonyBalanceRegion}")
	

********************************************************************************
* Additional Data Cleaning
********************************************************************************
	
* H2.1 treatment
clonevar hegemony_region_alt = hegemony_region
lab def hegreglabalt 0 "Africa" 1 "Control" 2 "Asia"
recode hegemony_region_alt (1=0) (3=1) (4=1)
lab val hegemony_region_alt hegreglabalt

* Hegemony

clonevar hegemony_concern = UMA315
lab var hegemony_concern "US Strengthening or Weakening"

* News interest

clonevar newsint_num = newsint
recode newsint_num (4 = 3) (7 = .)
lab def NEWSINT 3 "Now and then / hardly at all", modify


lab var hegemony_contribute "Contribute funds"
lab var hegemony_assist "Send experts in political campaigning"
lab var hegemony_fabricate "Fabricate and release damaging information"
lab var hegemony_promise "Promise to increase foreign aid"

	
gen hegemony_DV_3way = .
replace hegemony_DV_3way = 0 if hegemony_DV == 1 | hegemony_DV == 2
replace hegemony_DV_3way = 1 if hegemony_DV == 3
replace hegemony_DV_3way = 2 if hegemony_DV == 4 | hegemony_DV == 5
lab def hegemony_DV_3waylab 0 "Disapprove" 1 "Neither" 2 "Approve"
lab val hegemony_DV_3way hegemony_DV_3waylab


********************************************************************************
* Figure 4
********************************************************************************

/// Figure 4 a)

catplot 								 										///
	, over(hegemony_DV_3way, label(labsize(*.65)) )								///
	over(hegemony_region, label(labsize(2)))									///
	asyvars stack over(hegemony_high_chance)									///
	bar(1, bcolor(ebg)) bar(2, bcolor(dimgray)) 								///
	horizontal percent(hegemony_region hegemony_high_chance) 					///
	ytitle("Percent") 															///
	blabel(bar,format(%4.1f) size(2) position(center)) 							///
	legend(position(12) rows(1)) name(grhegemony_3way,replace)					///
	title("{bf:A) Support for Intervention by Region}", span)		
	

	
/// Figure 4 b)

* Treatment only
ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance
est sto	hegemony_base_olog, title("Base, Ologit")
local hegemony_base_ologN = e(N)

* With demographics 
ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7
est sto	hegemony_adj_olog, title("Adj, Ologit")
local 	hegemony_adj_ologN = e(N)
					
* Coefplot

local gtitle gph_overall

coefplot	(hegemony_base_olog,label(Base))									///
			(hegemony_adj_olog, label(Covariates))								///
			, title("{bf: B) Effects of Treatment on Intervention Support}", span)	///
			xtitle("{it: Ordinal Logistic Coefficients}", size(small) )			///
			keep(*.hegemony*) base												///
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			name(`gtitle',replace)  xline(0) 									///
			legend(ring(0) pos(1) rows(4) size(small)) 							///
			ylab(,labsize(vsmall))												///
			note("2022 CES Hegemony experiment. Base N = `hegemony_base_ologN'; Adj N = `hegemony_adj_ologN'." "Full specification for Adjusted includes party ID, gender, age, racial ID, college degree, and party ID.", size(vsmall) span)

********************
* Appendix Table A8

esttab hegemony_base_olog hegemony_adj_olog										///
		using "${MyProject}AppendixTableA8.tex"					///
		, replace nobase label 	longtable eqlabels(none) drop(cut*)				///
		mtitles("Base" "With Covariates")										///
		title("Hegemony Experiment Results" "\label{tab:hegemonyresults}")

		
	
/// Figure 4 c)

		
est restore hegemony_base_olog
margins, atmeans dydx(hegemony_high_chance) post
est sto hegemony_base_olog_dydx,title("Base")

mylabels -10(5)10, myscale(@/100) local(myla)

coefplot (hegemony_base_olog_dydx, label(Base))									///
		, recast(bar) vertical barw(0.25)										///
		ciopts(recast(rcap) color(gs8)) citop									///
		xlab(1 `""Strongly" "disapprove""' 2 "Disapprove" 3  "Neither"			///
			4 "Approve" 5 `""Strongly" "approve""',								///
			labsize(vsmall)) 													///
		title("{bf:C) Differences in Predicted Outcomes}", size(small) span) 	///
		subtitle("{it: High minus Low Condition; Base Model}",  size(small) span)	///
		yline(0) ylab(`myla',labsize(vsmall))									///
		name(gph_dydx, replace) 												///
		ytitle("Difference between conditions", size(vsmall)) 					///
		legend(off) 


gr combine grhegemony_3way gph_overall gph_dydx, rows(3) 
graph display, ysize(9) xsize(6)

********************
* Main Paper Figure 4

graph export "${MyProject}00 Main Figure 4.pdf", replace

********************************************************************************
* Appendix Extensions
********************************************************************************


* News Interest (Media Exposure)

local addon newsint

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white college i.pid7 if newsint_num == 1
est sto	subset_olog_`addon'1
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if newsint_num == 2
est sto	subset_olog_`addon'2
local 	N2 = e(N)


ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if newsint_num == 3
est sto	subset_olog_`addon'3
local 	N3 = e(N)


coefplot	(subset_olog_`addon'1, label(Most (`N1')))		///
			(subset_olog_`addon'2, label(Some (`N2')))	///
			(subset_olog_`addon'3, label(Rarely (`N3')))	///
			, title("{it: News Interest}")												///
			keep(*.hegemony*) base												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(8) rows(3) size(vsmall)) 							///
			name(g_`addon', replace)  xline(0) 									

* Hegemony

local addon hegemony

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white college i.pid7 if hegemony_concern == 1
est sto	subset_olog_`addon'1
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if hegemony_concern == 2
est sto	subset_olog_`addon'2
local 	N2 = e(N)


ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if hegemony_concern == 3
est sto	subset_olog_`addon'3
local 	N3 = e(N)


coefplot	(subset_olog_`addon'1, label(Weaker (`N1')))		///
			(subset_olog_`addon'2, label(Same (`N2')))	///
			(subset_olog_`addon'3, label(Stronger (`N3')))	///
			, title("{it: US Position in World}")								///
			keep(*.hegemony*) base												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(8) rows(3) size(vsmall)) 							///
			name(g_`addon', replace)  xline(0) 									

* Gender

local addon female

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white college i.pid7 if female == 0
est sto	subset_olog_`addon'0
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if female == 1
est sto	subset_olog_`addon'1
local 	N2 = e(N)

coefplot	(subset_olog_`addon'0, label(Male (`N1')))		///
			(subset_olog_`addon'1, label(Female (`N2')))	///
			, title("{it: Gender}")												///
			keep(*.hegemony*) base												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(1) rows(2) size(vsmall)) 							///
			name(g_gender,replace)  xline(0) 									

* Education


local addon college

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female  i.pid7 if college == 0
est sto	subset_olog_`addon'0
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female i.pid7 if college == 1
est sto	subset_olog_`addon'1
local 	N2 = e(N)


coefplot	(subset_olog_`addon'0, label(No College (`N1')))				///
			(subset_olog_`addon'1, label(College (`N2')))					///
			, title("{it: College}")											///
			keep(*.hegemony*) base												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(1) rows(2) size(vsmall)) 							///
			name(g_college,replace)  xline(0) 									

* Party ID


local addon pid7

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college  if pid7 <= 3 & pid7 != 8
est sto	subset_olog_`addon'Dem
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college   if pid7 == 4 
est sto	subset_olog_`addon'Ind
local 	N2 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college  if pid7 >= 5 & pid7 != 8
est sto	subset_olog_`addon'Gop
local 	N3 = e(N)


coefplot	(subset_olog_`addon'Dem, label(Democrats (`N1')))					///
			(subset_olog_`addon'Ind, label(Independents (`N2')))				///
			(subset_olog_`addon'Gop, label(Republicans (`N3')))				///
			, title("{it: Party ID}")											///
			keep(*.hegemony*) base												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(7) rows(3) size(vsmall)) 							///
			name(g_pid,replace)  xline(0) 									



* Ukraine Intervene

local addon ukraine

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if ukraineintervene2way == 0
est sto	subset_olog_`addon'0
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if ukraineintervene2way == 1
est sto	subset_olog_`addon'1
local 	N2 = e(N)


coefplot	(subset_olog_`addon'0, label(No Intervention (`N1')))					///
			(subset_olog_`addon'1, label(Intervene (`N2')))					///
			, title("{it: Ukraine}")												///
			keep(*.hegemony*) base												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(8) rows(2) size(vsmall)) 							///
			name(g_ukraine,replace)  xline(0) 		


* Political knowledge

local addon know

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if politicalknowledge == 0
est sto	subset_olog_`addon'0
local 	N1 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if politicalknowledge == 1
est sto	subset_olog_`addon'1
local 	N2 = e(N)

ologit	hegemony_DV i.hegemony_region i.hegemony_high_chance 					///
					age white female college i.pid7 if politicalknowledge == 2
est sto	subset_olog_`addon'2
local 	N3 = e(N)

coefplot	(subset_olog_`addon'0, label(Knowledge = 0 (`N1')))					///
			(subset_olog_`addon'1, label(Knowledge = 1 (`N2')))					///
			(subset_olog_`addon'1, label(Knowledge = 2 (`N3')))					///
			, title("{it: Knowledge}")												///
			levels(95 83 )  ciopts(lwidth(.75...) lcolor(*.4 *.9)) 				///	
			keep(*.hegemony*) base												///
			headings(1.hegemony_region = "{bf:Region}"							///
					0.hegemony_high_chance = "{bf:Ending US Leadership}"		///
						, labsize(vsmall))										///
			legend(ring(0) pos(11) rows(3) size(vsmall)) 							///
			name(g_know,replace)  xline(0) 		

********************
* Appendix Figure A6
					
gr combine g_gender g_pid g_newsint g_hegemony g_ukraine g_know				///
			, rows(3) xcommon 

graph display, ysize(7) xsize(10)

gr export "${MyProject}01 Figure A6.pdf", replace




********************************************************************************
* Strategy Analysis (Second DV, Appendix Only)
********************************************************************************

local strategies contribute promise fabricate assist 

foreach var of local strategies {
	local title = proper("`var'")

	local modelname olog
	quietly ologit hegemony_`var' i.hegemony_region i.hegemony_high_chance
	local `var'_n1 = e(N)
	local n1 = e(N)
	eststo strat_`var'_base
	
	quietly ologit hegemony_`var' i.hegemony_region i.hegemony_high_chance		///
		age white female college i.pid7
	local `var'_n2 = e(N)
	local n2 = e(N)
	eststo strat_`var'_cov
	
	}

********************
* Appendix Table A9

esttab strat_contribute_base strat_promise_base strat_fabricate_base strat_assist_base	///
		strat_contribute_cov strat_promise_cov strat_fabricate_cov strat_assist_cov		///
		using "${MyProject}AppendixTableA9.tex"				///
		, replace nobase label 	longtable eqlabels(none) drop(cut*)				///
		mtitles("Contribute" "Promise" "Fabricate" "Assist" 					///
			"Contribute" "Promise" "Fabricate" "Assist")						///
		title("Hegemony Experiment Results, By Strategy" "\label{tab:hegemonystratresults}")
